package com.vf.admin.client.controller.oss;

import com.aliyun.oss.OSSClient;
import com.aliyun.oss.model.PolicyConditions;
import com.aliyuncs.auth.sts.AssumeRoleResponse;
import com.google.gson.internal.$Gson$Types;
import com.vf.admin.client.common.ClientBaseController;
import com.vf.admin.client.controller.oss.dto.StsDto;
import com.vf.admin.common.entity.Result;
import com.vf.admin.utils.Base64Image.AliyunOSSClientUtil;
import com.vf.admin.utils.aliyunoss.OssSTSUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Map;

/**
 * <p>Title : 阿里云oss前端获取token</p>
 * <p>Description : </p>
 * <p>DevelopTools : IDEA</p>
 * <p>DevelopSystem : Windows10</p>
 *
 * @Author : NemoMeng
 * @Date 2023/7/18 14:17
 */
@Controller
@RequestMapping("/app/ossSts")
public class OssSTSController extends ClientBaseController {


    /**
     * 生成临时访问密钥
     */
    @RequestMapping(value = "/getStsToken")
    @ResponseBody
    public Result authItemList() {
        try {
            AssumeRoleResponse response = OssSTSUtil.getOssSTS();
            StsDto stsDto = new StsDto();
            stsDto.setResponse(response);
            stsDto.setEndpoint("https://" + AliyunOSSClientUtil.ENDPOINT);
            stsDto.setBucketName(AliyunOSSClientUtil.BUCKETNAME);
            stsDto.setKey(AliyunOSSClientUtil.KEY);
            stsDto.setUrl(AliyunOSSClientUtil.URL);


            return sucessJSON(stsDto);
        } catch (Exception e) {
            return errorJSON("获取失败");
        }

    }

    @RequestMapping(value = "/getStsTokenWx")
    @ResponseBody
    public Result getStsTokenWx() {
        try {
            Map<String, String> ossSTSWx = OssSTSUtil.getOssSTSWx();


            return sucessJSON(ossSTSWx);
        } catch (Exception e) {
            return errorJSON("获取失败");
        }

    }



}
